package com.tools.cleanmaster.ui.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.tools.cleanmaster.CleanConstant;
import com.tools.cleanmaster.R;
import com.tools.cleanmaster.ui.base.SingleActivity;
import com.tools.cleanmaster.utils.CompatibilityHelper;
import com.tools.cleanmaster.utils.PackageUtils;

public class HelperActivity extends SingleActivity {

    public static final String ASSET_URI = "file:///android_asset/";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.help);
        //StatusBarUtil.setTransparent(this);

        Intent intent = getIntent();
        String filePath = "";
        if(intent != null){
            filePath = intent.getStringExtra(CleanConstant.CLAUSE_HTML_NAME);
        }
        WebView webview = findViewById(R.id.webview);
        webview.setVerticalScrollbarOverlay(true);
        WebSettings ws = webview.getSettings();
        ws.setJavaScriptEnabled(true);
        if (CompatibilityHelper.isHigherAndroid3_0()){
            webview.removeJavascriptInterface("searchBoxJavaBridge_");
            webview.removeJavascriptInterface("accessibility");
            webview.removeJavascriptInterface("accessibilityTraversal");
        }
        ws.setSaveFormData(false);
        ws.setSavePassword(false);
        ws.setSupportZoom(false);
        ws.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webview.addJavascriptInterface(new JavaScriptInterface(), "Android");
        webview.setBackgroundColor(Color.BLACK);
        webview.loadUrl(ASSET_URI + filePath);
    }

    public class JavaScriptInterface {
        @JavascriptInterface
        public String getVersion() {
            return CleanConstant.REAL_PACKAGE_NAME + PackageUtils.getVersionName(HelperActivity.this, CleanConstant.REAL_PACKAGE_NAME);
        }
    }

}
